package br.unb.ida.midialab.pedparq;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CustomAdapter extends BaseAdapter{
	
	@SuppressWarnings("rawtypes")
	private ArrayList _list;
	private Utils util = Utils.getInstance();
	Context _c;
	
//	public CustomAdapter(ArrayList dados, Context c) {
//		_list = dados;
//		_c = c;
//	}
	public CustomAdapter(ArrayList<Atividade> listAt, Context c) {
		_list = listAt;
		_c = c;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return _list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return _list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		if(view == null){
			LayoutInflater vi = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = vi.inflate(R.layout.list_item_atividade, null);
		}
		TextView idView		  = (TextView) view.findViewById(R.id.textID);
		TextView dataView 	  = (TextView) view.findViewById(R.id.textData);
		TextView distanceView = (TextView) view.findViewById(R.id.textDistance);
		TextView duracaoView  = (TextView) view.findViewById(R.id.textDuracao);
		TextView pontosView	  = (TextView) view.findViewById(R.id.textPontos);
		
		Atividade at = (Atividade) _list.get(position);
		
		//TODO tratar data
		String fullDate = util.montarData(at.getDate());
		
		idView.setText(at.getId());
		dataView.setText(fullDate);
		distanceView.setText(String.valueOf(at.getDistancia()));
		duracaoView.setText(util.tempoToString(at.getTempoAtividade()));
		pontosView.setText(String.valueOf(at.getPassos()));
		
		return view;
	}
	

}
